Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compatibility with rfc2822 comments #733

Merged
merged 2 commits into from
Jul 24, 2022

Conversation

Finomnis
Copy link
Contributor

@Finomnis Finomnis commented Jul 9, 2022

Fixes #732.

@Finomnis Finomnis force-pushed the rfc2822_comments branch 6 times, most recently from 276bf3b to dcdc18c Compare July 10, 2022 07:28
Copy link
Collaborator

@esheppa esheppa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my perspective - I've just left one comment for some discussion

"Tue, 20 Jan 2015 17:35:20 -0800 ( (UTC ) (\\( (a)\\(( \\t ) ) \\\\( \\) ))",
Ok("Tue, 20 Jan 2015 17:35:20 -0800"),
), // complex trailing comment
("Tue, 20 Jan 2015 17:35:20 -0800 (UTC\\)", Err(TOO_LONG)), // incorrect comment, not enough closing parentheses
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like TOO_SHORT is more optimal in this case (admittedly obscure) - but it seems like actually getting TOO_SHORT at this stage might not be trivial, unless we early return from scan::comment_2822. Potentially the logic could be that if there is at least one ( then it makes sense to early return the TOO_SHORT if it is never closed. Alternatively, the parser could be more permissive and just remove all the comment characters and return the parsed date if the rest is in the correct format - let me know what your thoughts are here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had the same thought, but for one, it's indeed not trivial to change that; and further, it's not completely clear. Technically "Tue, 20 Jan 2015 17:35:20 -0800 (" could be both too short or too long. "Tue, 20 Jan 2015 17:35:20 -0800 x", for example, is definitely too long, so one could argue that the first one is also a valid string plus " (". So I'd argue that "a comment" is everything that parses as a comment, and "too long" is everything attached to the timestamp that doesn't parse as a comment. Which includes " (".

Copy link
Contributor Author

@Finomnis Finomnis Jul 16, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think just accepting everything is the right choice, at least not with your current code structure. parse.rs just parses a single rfc2822 datetime string, and the way it is currently written means it could be used as a part of a more complex parser. So I wouldn't allow just everything, otherwise I think the entire TOO_LONG value would be pointless and we could simply accept all the strings that start with a valid rfc2822 datetime.

If you want me to change something, then what I would agree with most is to short-circuit TOO_SHORT. But that also wouldn't be true the way the code is written right now, because the parse_rfc2822 conceptually is supposed to attempt to parse a rfc2822 datetime string + return the leftover input that wasn't part of the rfc2822 datetime. And it does exactly that in the case of "Tue, 20 Jan 2015 17:35:20 -0800 (", because "Tue, 20 Jan 2015 17:35:20 -0800" is a valid rfc2822 string and " (" is a valid rest. It just wasn't able to consume " (", which is totally valid.

So if we want to change something, it must be somewhere in the method parse_internal. And this one currently is written so that it always returns TOO_LONG whenever any tokens are left over from parsing. So I'm not sure how TOO_SHORT would conceptually fit the current code structure.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Finomnis - really good point about the rfc2822 item being able to be reused within other formats, we definitely shouldn't break that so it looks like it is best to leave it as is.

@Finomnis
Copy link
Contributor Author

@esheppa Rebased to fix merge conflict in CHANGELOG.md

@esheppa
Copy link
Collaborator

esheppa commented Jul 24, 2022

Thanks @Finomnis

@esheppa esheppa merged commit acd4ecf into chronotope:main Jul 24, 2022
@Finomnis Finomnis deleted the rfc2822_comments branch July 24, 2022 14:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DateTime::parse_from_rfc2822 not compliant with RFC2822 comments
2 participants